//
//  QZRightPopVC.m
//  map
//
//  Created by 000 on 16/7/28.
//  Copyright © 2016年 faner. All rights reserved.
//

#import "QZRightPopVC.h"
#import "QZGoodsModel.h"

@interface QZRightPopVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *sorceArray;
@property (nonatomic, assign) int k;
//@property (nonatomic, assign) int i;
//@property (n)

- (IBAction)backBtnClick;
- (IBAction)determineBtnClick;
@end

@implementation QZRightPopVC


- (NSString *)selecteText
{
    if (_selecteText == nil) {
        _selecteText = @"你好";
    }
    return _selecteText;
}
//资源
- (NSArray *)sorceArray
{
    if (_sorceArray ==nil) {
        _sorceArray = [QZGoodsModel goodsModels];
    }
    return _sorceArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.i =0;
    self.k = 0;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backBtnClick {
    
    self.selecteText = @"你好";
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)determineBtnClick {
    if ([self.delegate respondsToSelector:@selector(rightPopVC:didDetermineBtnClickWithI:)]) {
        [self.delegate rightPopVC:self didDetermineBtnClickWithI:self.k];
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.sorceArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    QZGoodsModel *goodsModel = self.sorceArray[indexPath.row];
    cell.textLabel.text = goodsModel.title;
    cell.imageView.image = [UIImage imageNamed:goodsModel.image] ;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.k = (int)indexPath.row;
    QZGoodsModel *goodsModel = self.sorceArray[indexPath.row];
    self.selecteText = goodsModel.title;
    self.imageStr = goodsModel.image;
//    NSLog(@"%@",self.imageStr);
//    self.i++;
//    NSLog(@"%@",self.selecteText);
}

@end
